package pos.utils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;

public class FlujoEntrada implements Iterable<String> {
	private String nf;
	
	public FlujoEntrada(String f) {
		nf = f;
	}
	
	public Iterator<String> iterator() {
		return new IteradorFlujoEntrada();	
	}
	
	private class IteradorFlujoEntrada implements Iterator<String> {
		private BufferedReader bf;
		private String linea;	
		
		public IteradorFlujoEntrada() {
			try {
				bf = new BufferedReader(new FileReader(nf));
				linea = bf.readLine();
			}
			catch(IOException e) {
				throw new IllegalArgumentException("No se puede acceder al fichero de entrada");
			}
		}
		
		public boolean hasNext() { 	
			return linea != null; 
		}

		public String next() {
			String pal = linea;
			
			try {
				linea = bf.readLine();
			}
			catch(IOException e) {
				throw new IllegalArgumentException("No se puede acceder al fichero de entrada");
			}
			
			return pal;
		}

		public void remove() {
			throw new UnsupportedOperationException();
		}		
	}
}
